package cool.qingqing.error;

import javax.servlet.http.HttpServletRequest;

import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cool.qingqing.result.Result;
import cool.qingqing.result.ResultEnum;

@RestController
public class HttpErrorController implements ErrorController {

    private final static String ERROR_PATH = "/error";


    @RequestMapping(value = ERROR_PATH)
    public Result errorJson(HttpServletRequest request) {
        Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
        if(statusCode==404)
        return new Result().setCode(ResultEnum.FAIL).setMsg("页面操作问题");

        return null;
    }

    @Override
    public String getErrorPath() {
        return ERROR_PATH;
    }
}
